package com.shopping_back.mapper;

import com.shopping_back.pojo.entity.RefundRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 退款记录表 Mapper 接口
 * </p>
 *
 * @author Jack
 * @since 2025-07-12
 */
@Mapper
public interface RefundRecordMapper extends BaseMapper<RefundRecord> {

    @Select("SELECT rr.payment_id, rr.refund_sn, rr.refund_amount, rr.status, rr.reason " +
            "FROM refund_record rr " +
            "JOIN order_main om ON rr.refund_sn = om.order_sn " +
            "WHERE om.merchant_id = #{merchantId} " +
            "ORDER BY rr.create_time DESC " +
            "LIMIT #{pageSize} OFFSET #{offset}")
    List<RefundRecord> selectRefundsByMerchantId(Long merchantId, int pageSize, long offset);

    @Select("SELECT COUNT(*) " +
            "FROM refund_record rr " +
            "JOIN order_main om ON rr.payment_id = om.id " +
            "WHERE om.merchant_id = #{merchantId}")
    long countRefundsByMerchantId(Long merchantId);}
